package com.approval.approvalapp.knowledge.wj.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.WjBean;
import com.approval.approvalapp.util.DateUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by louyulin on 2019/4/28.
 */

public class WjRvAdapter extends RecyclerView.Adapter<WjRvAdapter.Holder> {

    List<WjBean> wjBeans;

    Context context;

    ClickItemListener listener;



    public void setWjBeans(List<WjBean> wjBeans,ClickItemListener listener) {
        this.wjBeans = wjBeans;
        this.listener = listener;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_wj,parent,false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv1.setText(wjBeans.get(position).getDF_NAME());
        String add_time = wjBeans.get(position).getDF_TIME();
        holder.tv2.setText(add_time);
        if (wjBeans.get(position).getDF_TYPE() == 0){
            holder.tv3.setText("文件");
        }else if (wjBeans.get(position).getDF_TYPE() == 1){
            holder.tv3.setText("通用文档");
        }else {
            holder.tv3.setText("共享文档");
        }

        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.click(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (wjBeans == null){
            return 0;
        }else {
            return wjBeans.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder{
        TextView tv1 , tv2,tv3;
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            root = itemView.findViewById(R.id.root);
            tv1 = itemView.findViewById(R.id.tv1);
            tv2 = itemView.findViewById(R.id.tv2);
            tv3 = itemView.findViewById(R.id.tv3);
        }
    }

    public interface  ClickItemListener{
        public void click(int index);
    }
}
